﻿<Window x:Class="Cronus.Windows.EditEvents"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:Cronus.Windows"
        Title="Edit Events" Height="400" Width="500"
        Icon="/Cronus;component/Resources/FireCreature.ico" WindowStyle="ToolWindow">
    <Window.Resources>
        <local:TasksToDisplay x:Key="TasksToDisplayResource" />
        <ObjectDataProvider x:Key="TasksToDisplay"
                            ObjectType="{x:Type local:EditEvents}"
                            MethodName="GetAllTasksToSelectFrom" />
        <DataTemplate x:Key="TaskListComboBoxForEventList" DataType="EventsRow">
            <ComboBox IsTextSearchEnabled="True" HorizontalAlignment="Stretch"
                      IsEnabled="{Binding Path=IsEventDone}"
                      ItemsSource="{Binding Source={StaticResource TasksToDisplay}}"
                      SelectedValue="{Binding Mode=TwoWay,Path=TasksRow}" />
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="45" />
            <RowDefinition Height="65" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="110" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        
        <!--Prompt the user for a date to view/modify events for.-->
        <GroupBox Header="Enter Date" Grid.Row="0" Grid.Column="0">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="90" />
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <TextBox Name="_DateTextBox" Grid.Column="0"
                         VerticalAlignment="Center"
                         LostFocus="DateTextBox_LostFocus"
                         KeyDown="DateTextBox_KeyDown" />
            </Grid>
        </GroupBox>
        
        <GroupBox Header="Add Event" Grid.Row="1"
                  Grid.Column="0" Grid.ColumnSpan="2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="15" />
                    <RowDefinition Height="30" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition Width="75" />
                </Grid.ColumnDefinitions>
                
                <!--Text labels so users know which field is what.-->
                <TextBlock Grid.Column="0" Grid.Row="0" Text="Start Time"
                           VerticalAlignment="Center" HorizontalAlignment="Center" />
                <TextBlock Grid.Column="1" Grid.Row="0" Text="End Time"
                           VerticalAlignment="Center" HorizontalAlignment="Center" />
                <TextBlock Grid.Column="2" Grid.Row="0" Text="Task"
                           VerticalAlignment="Center" HorizontalAlignment="Center" />
                
                <!--User input controls-->
                <TextBox Name="_StartTimeTextBox" VerticalAlignment="Center"
                         Grid.Column="0" Grid.Row="1"
                         LostFocus="AddTimeTextBox_LostFocus" />
                <TextBox Name="_EndTimeTextBox" VerticalAlignment="Center"
                         Grid.Column="1" Grid.Row="1"
                         LostFocus="AddTimeTextBox_LostFocus" />
                <ComboBox Name="_TaskListCombo" VerticalAlignment="Center"
                          ItemsSource="{Binding Source={StaticResource TasksToDisplayResource}}"
                          SelectedIndex="0" Grid.Column="2" Grid.Row="1" IsTextSearchEnabled="True" />
                <Button Name="_AddEventBtn" Content="Add Event"
                        VerticalAlignment="Center" Click="AddEventBtn_Click"
                        Grid.Column="4" Grid.Row="0" Grid.RowSpan="2" />
            </Grid>
        </GroupBox>
        
        <!--Show the users all of the events for the selected day.-->
        <GroupBox Header="Events"
                  Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="25" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="125" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="75" />
                </Grid.ColumnDefinitions>
                
                <!--Tell the user the total number of hours for the day shown.-->
                <TextBlock Name="_TotalEventsTime" Grid.Row="0" Grid.Column="0"
                           VerticalAlignment="Center" HorizontalAlignment="Center" />
                
                <!--The delete event button.-->
                <Button Name="_DeleteEventBtn" Grid.Row="0" Grid.Column="2"
                        Content="Delete Event" Click="DeleteEventBtn_Click"
                        HorizontalAlignment="Center" VerticalAlignment="Center" />
                         
                <!--Main display of events.-->
                <ListView Name="_EventListView" SelectionMode="Single"
                          SelectionChanged="EventListView_SelectionChanged"
                          Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3">
                    <ListView.Resources>
                        <!--Tells the items in the list view to stretch if they set the HorizontalAlignment
                        to Stretch.  Really only used for the Combobox TaskName column.-->
                        <Style TargetType="ListViewItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        </Style>
                    </ListView.Resources>
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Start Time" Width="85">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding Path=StartTimeString}" Width="75"
                                                 LostFocus="GridColumn_LostFocus"
                                                 KeyDown="GridColumn_KeyDown"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="End Time" Width="85">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding Path=EndTimeString}" Width="75"
                                                 LostFocus="GridColumn_LostFocus"
                                                 KeyDown="GridColumn_KeyDown"
                                                 IsEnabled="{Binding Path=IsEventDone}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn DisplayMemberBinding="{Binding Path=EventDurationString}"
                                            Header="Duration" Width="65" />
                            <GridViewColumn Header="Task Name" Width="200"
                                            CellTemplate="{StaticResource TaskListComboBoxForEventList}" />
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>
        </GroupBox>
    </Grid>
</Window>
